﻿namespace ACCOUNTING.LVY.Business
{
    using ACCOUNTING;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Data;
    using System.Windows.Forms;

    public class clsSanPhamDoDang
    {
        private string mDienGiai = "";
        private string mKhoaBoPhan = "";
        private string mKhoaDonVi = "";
        private string mKhoaHopDong = "";
        private string mKhoaSanPham = "";
        private string mKhoaTaiKhoanCo = "";
        private string mKhoaTaiKhoanNo = "";
        private string mLoaiTien = "";
        private string mNamThang = "";
        private double mSoPhatSinh = 0.0;
        private double mSoPhatSinhNT = 0.0;
        private double mTyGia = 0.0;

        public DataTable GetSanPhamDoDang()
        {
            string commandText = "SELECT C.KhoaTaiKhoanNo As KhoaTaiKhoanNo, Rtrim(TKN.SoTaiKhoan) + '.' + TKN.Ten" + modGeneral.H_LANGUAGE + " as SoTaiKhoanNo,  C.KhoaTaiKhoanCo As KhoaTaiKhoanCo, Rtrim(TKC.SoTaiKhoan) + '.' + TKC.Ten" + modGeneral.H_LANGUAGE + " as SoTaiKhoanCo,  C.KhoaBoPhan, BP.Ten" + modGeneral.H_LANGUAGE + " as BoPhan, C.KhoaSanPham, SP.Ten" + modGeneral.H_LANGUAGE + " as SanPham ,  C.KhoaHopDong, HD.SoHopDong, C.SoPhatSinhNT As SoPhatSinh, C.DienGiai FROM GL_SanPhamDoDang C  LEFT JOIN DM_TaiKhoan TKN on C.KhoaTaiKhoanNo = TKN.Khoa  LEFT JOIN DM_TaiKhoan TKC on C.KhoaTaiKhoanCo = TKC.Khoa  LEFT JOIN DM_DonViBoPhan BP on C.KhoaBoPhan = BP.Khoa  LEFT JOIN DM_SanPhamCongViec SP on C.KhoaSanPham = SP.Khoa  LEFT JOIN DM_HopDong HD on C.KhoaHopDong = HD.Khoa  WHERE C.NamThang = '" + this.mNamThang + "' AND C.KhoaDonVi = '" + this.mKhoaDonVi + "'";
            return DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
        }

        public bool GhiSo(string pKhoaChungTu, string pSoChungTu, string pNgayChungTu)
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[6];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@NamThang", DbType.Int64, ParameterDirection.Input, this.mNamThang);
                commandParameters[1] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, this.mKhoaDonVi);
                commandParameters[2] = DBHelper.createParameter("@KhoaChungTu", DbType.Int64, ParameterDirection.Input, pKhoaChungTu);
                commandParameters[3] = DBHelper.createParameter("@SoChungTu", DbType.Int64, ParameterDirection.Input, pSoChungTu);
                commandParameters[4] = DBHelper.createParameter("@NgayChungTu", DbType.Int64, ParameterDirection.Input, pNgayChungTu);
                commandParameters[5] = DBHelper.createParameter("@pError", DbType.Double, ParameterDirection.Output, 0);
                DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "GL_sp_GhiSoSanPhamDoDang", commandParameters);
                flag = Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectEqual(commandParameters[5].Value, 0, false);
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool HuyGhiSo(string pKhoaChungTu)
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[4];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@NamThang", DbType.Int64, ParameterDirection.Input, this.mNamThang);
                commandParameters[1] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, this.mKhoaDonVi);
                commandParameters[2] = DBHelper.createParameter("@KhoaChungTu", DbType.Int64, ParameterDirection.Input, pKhoaChungTu);
                commandParameters[3] = DBHelper.createParameter("@pError", DbType.Double, ParameterDirection.Output, 0);
                DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "GL_sp_SanPhamDoDangDel", commandParameters);
                flag = Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectEqual(commandParameters[3].Value, 0, false);
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool Save()
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[0x10];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@NamThang", DbType.Int64, ParameterDirection.Input, this.mNamThang);
                commandParameters[1] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, this.mKhoaDonVi);
                commandParameters[2] = DBHelper.createParameter("@KhoaTaiKhoanNo", DbType.Int64, ParameterDirection.Input, this.mKhoaTaiKhoanNo);
                commandParameters[3] = DBHelper.createParameter("@KhoaTaiKhoanCo", DbType.Int64, ParameterDirection.Input, this.mKhoaTaiKhoanCo);
                commandParameters[4] = DBHelper.createParameter("@KhoaBoPhan", DbType.Int64, ParameterDirection.Input, this.mKhoaBoPhan);
                commandParameters[5] = DBHelper.createParameter("@KhoaSanPham", DbType.Int64, ParameterDirection.Input, this.mKhoaSanPham);
                commandParameters[6] = DBHelper.createParameter("@KhoaHopDong", DbType.Int64, ParameterDirection.Input, this.mKhoaHopDong);
                commandParameters[7] = DBHelper.createParameter("@LoaiTien", DbType.Int64, ParameterDirection.Input, this.mLoaiTien);
                commandParameters[8] = DBHelper.createParameter("@TyGia", DbType.Date, ParameterDirection.Input, this.mTyGia);
                commandParameters[9] = DBHelper.createParameter("@SoPhatSinhNT", DbType.Date, ParameterDirection.Input, this.mSoPhatSinhNT);
                commandParameters[10] = DBHelper.createParameter("@SoPhatSinh", DbType.Date, ParameterDirection.Input, this.mSoPhatSinh);
                commandParameters[11] = DBHelper.createParameter("@DienGiai", DbType.Int64, ParameterDirection.Input, this.mDienGiai);
                flag = DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "GL_sp_SanPhamDoDangTmp", commandParameters) > 0;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public DataTable TinhLaiSanPhamDoDang()
        {
            DataTable table;
            IDataParameter[] commandParameters = new IDataParameter[0x1a];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, this.mKhoaDonVi);
                commandParameters[1] = DBHelper.createParameter("@NamThang", DbType.Int64, ParameterDirection.Input, this.mNamThang);
                commandParameters[2] = DBHelper.createParameter("@Language", DbType.Int64, ParameterDirection.Input, modGeneral.H_LANGUAGE);
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.StoredProcedure, "GL_sp_GetChiPhiSanPhamDoDang", commandParameters).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public string DienGiai
        {
            get
            {
                return this.mDienGiai;
            }
            set
            {
                this.mDienGiai = value;
            }
        }

        public string KhoaBoPhan
        {
            get
            {
                return this.mKhoaBoPhan;
            }
            set
            {
                this.mKhoaBoPhan = value;
            }
        }

        public string KhoaDonVi
        {
            get
            {
                return this.mKhoaDonVi;
            }
            set
            {
                this.mKhoaDonVi = value;
            }
        }

        public string KhoaHopDong
        {
            get
            {
                return this.mKhoaHopDong;
            }
            set
            {
                this.mKhoaHopDong = value;
            }
        }

        public string KhoaSanPham
        {
            get
            {
                return this.mKhoaSanPham;
            }
            set
            {
                this.mKhoaSanPham = value;
            }
        }

        public string KhoaTaiKhoanCo
        {
            get
            {
                return this.mKhoaTaiKhoanCo;
            }
            set
            {
                this.mKhoaTaiKhoanCo = value;
            }
        }

        public string KhoaTaiKhoanNo
        {
            get
            {
                return this.mKhoaTaiKhoanNo;
            }
            set
            {
                this.mKhoaTaiKhoanNo = value;
            }
        }

        public string LoaiTien
        {
            get
            {
                return this.mLoaiTien;
            }
            set
            {
                this.mLoaiTien = value;
            }
        }

        public string NamThang
        {
            get
            {
                return this.mNamThang;
            }
            set
            {
                this.mNamThang = value;
            }
        }

        public double SoPhatSinh
        {
            get
            {
                return this.mSoPhatSinh;
            }
            set
            {
                this.mSoPhatSinh = value;
            }
        }

        public double SoPhatSinhNT
        {
            get
            {
                return this.mSoPhatSinhNT;
            }
            set
            {
                this.mSoPhatSinhNT = value;
            }
        }

        public double TyGia
        {
            get
            {
                return this.mTyGia;
            }
            set
            {
                this.mTyGia = value;
            }
        }
    }
}

